﻿using Microsoft.Extensions.Configuration;
using WebMvc.Utils.ConfigurationInfo;

namespace WebMvc.Utils
{
    public class ReadConfiguration
    {
        public static void Show(ConfigurationManager configurationManager)
        {
            WriteLine($"Id: {configurationManager["Id"]}");
            WriteLine($"Name: {configurationManager["Name"]}");
            WriteLine($"TeachInfo.Id: {configurationManager["TeachInfo:Id"]}");
            WriteLine($"TeachInfo.Name: {configurationManager["TeachInfo:Name"]}");
            WriteLine($"ConnectionStrings.WriteConnection: {configurationManager["ConnectionStrings:WriteConnection"]}");
            WriteLine($"ConnectionStrings.ReadConnectionList0: {configurationManager["ConnectionStrings:ReadConnectionList:0"]}");
            WriteLine($"ConnectionStrings.ReadConnectionList1: {configurationManager["ConnectionStrings:ReadConnectionList:1"]}");
            WriteLine($"ConnectionStrings.ReadConnectionList2: {configurationManager["ConnectionStrings:ReadConnectionList:2"]}");
        }

        public static void ShowBind(IConfiguration configuration)
        {
            var connectionStringOptions = new ConnectionStringOptions();

            configuration.Bind("ConnectionStrings", connectionStringOptions);

            Console.WriteLine(connectionStringOptions);
        }

        private static void WriteLine(Object? obj)
        {
            Console.WriteLine(obj?.ToString());
        }
    }
}
